﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddNewGroup_User.aspx.cs" Inherits="KhoaLuan.MainSys.Manager.GroupUser.AddNewGroup_User" %>

<div style="background: #fff; padding: 20px; margin: auto; clear: both; width: 500px; margin: auto; position: absolute; bottom: auto; left: 0; right: 0; vertical-align: middle;" id="divAddNewGroup_User">
    <script src="/Scripts/dluscript.js"></script>
    <div class="modal-header" style="height: 50px; background: #3276b1; text-align: center; margin-bottom: 20px; margin: -20px; color: white;">
        <span style="font-weight: bold; font-family: 'Open Sans',Arial,Helvetica,Sans-Serif; font-size: 20px; text-align: center;" runat="server" id="Title"></span>

        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="color: #fff !important; opacity: 1">
            &times;
        </button>
    </div>
    <div class="modal-body no-padding" style="background: white; margin-top: 20px;">
         
        <div id="smart-form-register" class="smart-form">
            <fieldset>
                <section>
                    <label class="label">Group</label>
                    <select id="drGroupId" runat="server" class="select2"></select>
                </section>
                  <section>
                    <label class="label">Người dùng</label>
                    <select id="drUserID" runat="server" class="select2"></select>
                </section>
            </fieldset>
            <footer>
                <input type="button" class="btn btn-default" value="Hủy" data-dismiss="modal" />
                <input type="button" class="btn btn-primary" value="Lưu" id="btnSave" />

            </footer>
        </div>
    </div>
    <div style="clear: both;"></div>

</div>
<script type="text/javascript">
    pageSetUp();
    var AddNewGroup_User = {
        Save: function () {
            var group = $('#drGroupId').val();
            var user = $('#drUserID').val();
           
            CallAjaxAspx("POST", "InserttbGroupUser", "/MainSys/ProcessAJAX/AjaxGroup_User.aspx", {
                GroupId: group,
                UserID: user
            }, function (response) {
                debugger;
                if (JSON.parse(response).Status) {
                    alertSmallBox("Thêm thành công Group", "2 giây trước");
                    window.location.reload();
                }
                else {
                    alertSmallBox("Thêm Group thất bại", "2 giây trước", "error");
                }
            }, function () {
                $("body").addClass("loading");
                //beforesend
            }, function () {
                //sendcomplete
                $("body").removeClass("loading");
            });
        },

        Update: function () {
            debugger;
            var group = $('#drGroupId').val();
            var user = $('#drUserID').val();
         
            CallAjaxAspx("POST", "UpdatetbGroupUser", "/MainSys/ProcessAJAX/AjaxGroup_User.aspx", {
                Group_UserID: currentGroup_User.Group_UserID,
                GroupId: group,
                UserID: user
            }, function (response) {
                if (JSON.parse(response).Status) {
                    alertSmallBox("Sửa thành công", "2 giây trước");
                    window.location.reload();
                }
                else {
                    alertSmallBox("Sửa thất bại", "2 giây trước", "error");
                }
            }, function () {
                $("body").addClass("loading");
                //beforesend
            }, function () {
                //sendcomplete
                $("body").removeClass("loading");
            });
        },


        FillData: function (groupuser) {
            $('#drGroupId').val(groupuser.GroupId);
            $('#drUserID').val(groupuser.UserID);
        }
    };


    $(document).ready(function () {
        if (typeof currentGroup_User !== 'undefined' && currentGroup_User != null) {
            $('#<%=Title.ClientID%>').text("CẬP NHẬT THÔNG TIN GROUP");
            debugger;

            AddNewGroup.FillData(currentGroup_User);
        }
        else {
            $('#<%=Title.ClientID%>').text("THÊM MỚI GROUP");
        }

        $("#divAddNewGroup_User").delay(500).fadeIn(500).verticalAlign(400);
        $("#btnSave").click(function () {
            debugger;
            if (typeof currentGroup_User !== 'undefined' && currentGroup_User != null)
                AddNewGroup_User.Update();
            else
                AddNewGroup_User.Save();
        });
    });
</script>
